package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingConstants;


public class StartLevelScreen extends JPanel implements ActionListener {

    private JButton b1;
    private JFrame myStartWindow;
    private boolean myActive;

    public StartLevelScreen () {
        // ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
        // ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
        // ImageIcon rightButtonIcon = createImageIcon("images/left.gif");

        // b1 = new JButton("Disable middle button", leftButtonIcon);
        b1 = new JButton("Begin next level");
        b1.setVerticalTextPosition(SwingConstants.CENTER);
        b1.setHorizontalTextPosition(SwingConstants.LEADING); // aka LEFT, for
                                                              // left-to-right
                                                              // locales
        b1.setMnemonic(KeyEvent.VK_ENTER);
        b1.setActionCommand("start");

        b1.addActionListener(this);

        b1.setToolTipText("Click this button to begin the next level of the game.");

        // Add Components to this container, using the default FlowLayout.
        add(b1);
        myActive = true;
        createAndShowGUI();
    }

    @Override
    public void actionPerformed (ActionEvent e) {
        if ("start".equals(e.getActionCommand())) {
            // load next game environment

            // start timer

            // close menu
            myStartWindow.dispose();
            // tell viewcontroller that it's closing
            myActive = false;
        }
    }

    /**
     * Create the GUI and show it. For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private void createAndShowGUI () {

        // Create and set up the window.
        myStartWindow = new JFrame("ButtonDemo");
        myStartWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create and set up the content pane.
        setOpaque(true); // content panes must be opaque
        myStartWindow.setContentPane(this);

        // Display the window.
        myStartWindow.pack();
        myStartWindow.setVisible(true);
    }

    public boolean isActive () {
        return myActive;
    }

}
